Ext.define('MyBlog.controller.EntryList', {
	extend: 'Ext.app.Controller',
	
	stores: ['EntryList'],
	
    models:['Entry'],
	
	views : ['EntryList'],
	
	init: function(){
		
		this.control({
			'entryList': {
				itemdblclick : this.openThisItem	
			}
		});
	},
	
	openThisItem: function(record, index){
		//console.log("selecciono item: " + index.get('id'));
		var entryTabPanel = Ext.getCmp('entryTabsId');
		var addFlag = true;
		for(var i = 0; i < entryTabPanel.items.items.length; i++){
			if(entryTabPanel.items.items[i].id == 'entryId-' + index.get('id')){
				addFlag = false;
			}
		}
		
		if(addFlag){
			entryTabPanel.add({
				id: 'entryId-' + index.get('id'),
				title: index.get('title'),
				html: index.get('entry'),
				closable: true
			});
			entryTabPanel.setActiveTab(entryTabPanel.items.items.length-1);
		}
		//Ext.getCmp('entryTabsId').setActiveTab(0);
	}
});